package de.jmda.core.util;

public abstract class ThreadLocalData<T>
{
	private final static ThreadLocal<ThreadLocalData<?>> THREAD_LOCAL =
	    new ThreadLocal<>();

	private T value;

	protected ThreadLocalData()
	{
		super();
		THREAD_LOCAL.set(this);
	}

	@SuppressWarnings("rawtypes")
	public static ThreadLocalData get()
	{
		return THREAD_LOCAL.get();
	}

	@SuppressWarnings("unchecked")
	public void setValue(T value)
	{
		get().value = value;
	}

	@SuppressWarnings("unchecked")
	public T getValue()
	{
		return (T) get().value;
	}

	protected static ThreadLocal<ThreadLocalData<?>> getThreadLocal()
	{
		return THREAD_LOCAL;
	}
}